<?php
namespace core\lib;
use core\lib\conf;

class route {

    static public $ctrl;
    static public $action;

    public function __construct() {
        /**
        * 1.隐藏index.php
        * 2.获取url部分 1./index/index/ 2./index 3./
        * 3.获取参数
        */
        $path = $_SERVER['REQUEST_URI'];
        if ( isset( $path ) && $path != '/' ) {
            $patharr = \explode( '/', trim( $path, '/' ) );

            if ( isset( $patharr[0] ) ) {
                self::$ctrl = $patharr[0];
                unset( $patharr[0] );
            }
            if ( isset( $patharr[1] ) ) {
                self::$action = $patharr[1];
                unset( $patharr[1] );
            }

            $count = count( $patharr )+2;
            $i = 2;
            while ( $i < $count ) {
                if ( isset( $patharr[$i+1] ) ) {
                    $_GET[$patharr[$i]] = $patharr[$i+1];
                }

                $i = $i+2;
            }

        } else {
            self::$ctrl = conf::get('ctrl');
            self::$action = conf::get('action');
        }
    }
}